<template>
  <component :is="current" :ref="current" v-model="innerValue" :cfg="cfg" />
</template>
<script>
import { CQ_EVAL_INPUT_MODE } from '@/utils/baseData'
import All from './AllInput'
import Option from './OptionInput'
const inputModeMap = {
  [CQ_EVAL_INPUT_MODE.ALL]: 'All',
  [CQ_EVAL_INPUT_MODE.OPTION]: 'Option'
}
export default {
  name: 'InputMode',
  components: { All, Option },
  props: {
    value: { type: Array, default: () => [] },
    cfg: { type: Object, default: () => ({}) }
  },
  computed: {
    innerValue: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      }
    },
    current() {
      const inputMode = this.cfg?.inputMode
      return inputModeMap[inputMode] || ''
    }
  },
  methods: {
    async validate() {
      return this.$refs[this.current]?.validate()
    }
  }
}
</script>
